package rabbit.client.produice;

import java.util.Properties;

import org.apache.kafka.clients.producer.KafkaProducer;
import org.apache.kafka.clients.producer.Producer;
import org.apache.kafka.clients.producer.ProducerRecord;

public class MyKafkaProduice {
	
	public static void main(String[] args) {
		//配置信息
		Properties props = new Properties();
		props.put ("bootstrap.servers","localhost:9092");
		//设置数据 key 的序列化处理类
		props.put("key.serializer", "org.apache.kafka.common.serialization.StringSerializer");
		//设置数据 value 的序列化处理类
		props.put("value.serializer", "org.apache.kafka.common.serialization.StringSerializer");
		//创建生产者实例
		Producer<String, String> producer= new KafkaProducer<>(props);
		//创建1条新的记录，第一个参数为 Topic 名称
		ProducerRecord<String,String> record = new ProducerRecord<String,String>("my-topic", "userName","song");
		producer.send(record);
		producer.close();
	}
}
